﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.ParagraphProperties
{
    [XmlRoot("numPr", Namespace = Constants.WordMain)]
    public class Numbering : XmlSerializable, IParagraphPropElement
    {
        [XmlElement("ilvl", Namespace = Constants.WordMain)]
        public NumberingLevelRef NumberingLevel { get; set; }

        [XmlElement("numId", Namespace = Constants.WordMain)]
        public NumberingDefinition NumId { get; set; }

        /// <summary>
        /// Previous Paragraph Numbering Properties
        /// </summary>
        [XmlElement("numberingChange", Namespace = Constants.WordMain)]
        public NumberingChange PrevParagraph { get; set; }

        [XmlElement("ins", Namespace = Constants.WordMain)]
        public InsertedNumbering Inserted { get; set; }

        public Numbering() { }

        public void Copy(object obj)
        {
            if (obj is Numbering)
            {
                this.Inserted = (obj as Numbering).Inserted;
                this.NumberingLevel = (obj as Numbering).NumberingLevel;
                this.NumId = (obj as Numbering).NumId;
                this.PrevParagraph = (obj as Numbering).PrevParagraph;
            }
        }
    }

    #region Classes

    #region NumberingLevelRef

    [XmlRoot("ilvl", Namespace = Constants.WordMain)]
    public class NumberingLevelRef : XmlSerializable
    {
        [XmlAttribute("val", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public int Value { get; set; }

        public NumberingLevelRef() { }
    }

    #endregion

    #region NumberingDefinition

    [XmlRoot("numId", Namespace = Constants.WordMain)]
    public class NumberingDefinition : XmlSerializable
    {
        [XmlAttribute("val", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public int Value { get; set; }

        public NumberingDefinition() { }
    }

    #endregion

    #region NumberingChange

    [XmlRoot("numberingChange", Namespace = Constants.WordMain)]
    public class NumberingChange : XmlSerializable
    {
        [XmlAttribute("id", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public int Id { get; set; }

        [XmlAttribute("author", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public string Author { get; set; }

        [Optional]
        [XmlAttribute("date", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public DateTime Time { get; set; }

        [Optional]
        [XmlAttribute("original", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public string PrevNumberingValue { get; set; }

        public NumberingChange() { }
    }

    #endregion

    #region InsertedNumbering

    [XmlRoot("ins", Namespace = Constants.WordMain)]
    public class InsertedNumbering : XmlSerializable
    {
        [XmlAttribute("id", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public int Id { get; set; }

        [XmlAttribute("author", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public string Author { get; set; }

        [Optional]
        [XmlAttribute("date", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public DateTime Time { get; set; }

        public InsertedNumbering() { }
    }

    #endregion

    #endregion
}
